<?php
require('../configs/include.php');
require(C_FULL_PATH . 'modules/m_phpass/PasswordHash.php');

class c_editar_sonido extends super_controller {

    
       public function sonidos(){
           
                   
        $options['sonido']['lvl2'] = "nombre";
        $this->orm->connect();
        $this->orm->read_data(array("sonido"), $options);
        $sonido = $this->orm->get_objects("sonido");
        $this->orm->close();
        $this->engine->assign('sonido', $sonido);
       
            
    } 
    public function buscar(){       
        $cod['sonido']['id'] = $_POST["id"];
        $options['sonido']['lvl2'] = "one";
        
        $this->orm->connect();
        $this->orm->read_data(array("sonido"), $options, $cod);
        $sonido = $this->orm->get_objects("sonido");
        $this->orm->close();
        $this->engine->assign('aux', $sonido);      
        $this->engine->assign('id_sonido', $sonido[0]->get('id'));    
        $this->historias($_POST["id"]);
        $this->sonidos();
    }
    public function buscar2(){       
        $cod['sonido']['id'] = $_GET["id"];
        $options['sonido']['lvl2'] = "one";
        
        $this->orm->connect();
        $this->orm->read_data(array("sonido"), $options, $cod);
        $sonido = $this->orm->get_objects("sonido");
        $this->orm->close();
        $this->engine->assign('aux', $sonido);    
         $this->engine->assign('id_sonido', $sonido[0]->get('id')); 
        $this->historias($_GET["id"]);
        $this->sonidos();
    }
     public function editar(){
            $sonido = new sonido($this->post);
            $options = "update";
                           
            $this->orm->connect();
            $this->orm->update_data($options, $sonido);
            $this->orm->close();

            $this->type_warning = "success";
            $this->msg_warning = "sonido actualizado correctamente!";
            $this->engine->assign('type_warning', $this->type_warning);
            $this->engine->assign('msg_warning', $this->msg_warning);
            $this->temp_aux = 'message.tpl';
          }

     
    public function SeleccionarVidejuego(){
        $options['videojuego']['lvl2'] = "all";
        $this->orm->connect();
        $this->orm->read_data(array("videojuego"), $options);
        $videojuego = $this->orm->get_objects("videojuego");
        $this->orm->close();
        $this->engine->assign('videojuego', $videojuego);         
    }
             
    public function historias($id){
        
        $cod['historia']['videojuego'] = $id;
        $options['historia']['lvl2'] = "videojuego";
        $this->orm->connect();
        $this->orm->read_data(array("historia"), $options, $cod);
        $historia = $this->orm->get_objects("historia");
        $this->orm->close();
        $this->engine->assign('historia', $historia);
    }
    public function movimiento(){
    $options['movimiento']['lvl2']="nombre";    
        $this->orm->connect();
        $this->orm->read_data(array("movimiento"), $options);
        $movimiento = $this->orm->get_objects("movimiento");
        $this->orm->close();
        $this->engine->assign('movimiento', $movimiento);
    }
    
   
    public function display() {
        $this->sonidos();
        $this->movimiento();
        $this->SeleccionarVidejuego();
        
        $this->engine->assign('title', 'Editar sonido');
        $this->engine->display('header.tpl');
         if ($this->error == 1) {
            $this->engine->assign('obj', $this->post);
            $this->engine->assign('type_warning', $this->type_warning);
            $this->engine->assign('msg_warning', $this->msg_warning);
            $this->temp_aux = 'message.tpl';
        }
        $this->engine->display($this->temp_aux);
        $this->engine->display('editar_sonido.tpl');
        $this->engine->display('footer.tpl');
    }

    public function run() {
        try {
            if (isset($this->get->option)) {
                $this->{$this->get->option}();
            }
        } catch (Exception $e) {
            $this->error = 1;
            $this->msg_warning = $e->getMessage();
        }
        $this->display();
    }

}

$call = new c_editar_sonido();
$call->run();
?>
